package com.wechat.process.message;

import com.wechat.constants.WechatConstants;
import com.wechat.pojo.WechatImageMessage;
import com.wechat.pojo.WechatMessage;
import com.wechat.utils.XmlUtils;
import lombok.Setter;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author why
 * @date 2018/3/1 0001
 */
public class WechatImageMessageProcess implements WechatMessageProcessInterface {

    @Setter
    private String openId;

    @Setter
    private String mediaId;

    @Override
    public void autoReplyWechatMessage(PrintWriter wechatWriter) {
        String msg = getWechatImageMessage(mediaId);
        wechatWriter.write(msg);
    }

    public String getWechatImageMessage(String mediaId) {
        WechatMessage wechatMessage = getWechatMessage(openId);
        List<WechatImageMessage.Image> imageList = new ArrayList<WechatImageMessage.Image>();
        WechatImageMessage.Image image = new WechatImageMessage.Image(mediaId);
        imageList.add(image);
        String imageMessage = XmlUtils.objectConvertToXml(new WechatImageMessage(wechatMessage.getToUserName(), wechatMessage.getFromUserName(),
                wechatMessage.getCreateTime(), WechatConstants.XmlMsgType.IMAGE, imageList));
        return imageMessage;
    }


}
